<template>
    <div class="menu_manage_span">
        <table-span
                :current-page="tabelData.current"
                :page-size="tabelData.size"
                :total="tabelData.total"
                :isShowTool="false"
                :size-change="handleSizeChange" 
                :current-change="handleCurrentChange">
            <template v-slot:searchItem>
                <div class="search_item_span search_item_fix_width">
                    <el-input size="default" v-model="menuSearchCondition.menuName"
                        placeholder="请输入菜单名称" clearable></el-input>
                </div>
                <div class="search_item_span">
                    <el-select v-model="menuSearchCondition.parentId" placeholder="请选择一级菜单"
                               size="default" clearable>
                        <el-option
                                v-for="item in parentList"
                                :key="item.menuId"
                                :label="item.menuName"
                                :value="item.menuId">
                        </el-option>
                    </el-select>
                </div>
                <div class="search_item_span">
                    <el-select v-model="menuSearchCondition.menuLevel" placeholder="请选择菜单级别"
                               size="default" clearable>
                        <el-option
                                v-for="item in menuLevelList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </div>
                <div class="search_item_span">
                    <el-button icon="Search" size="default" type="primary" @click="searchData">查询</el-button>
                </div>

                <div class="search_item_span">
                    <el-button icon="Plus" size="default"
                        type="primary" :disabled="!(btOption.btSaveMenu)"
                        @click="btInsertMenu">新增菜单</el-button>
                </div>
            </template>

            <template v-slot:searchTable>
                <el-table :data="tabelData.records"
                    size="default" height="100%" style="width: 100%;">
                    <el-table-column
                        align="center"
                        type="index"
                        width="50">
                    </el-table-column>
                    <el-table-column
                        align="center"
                        prop="parentName"
                        label="父级菜单"
                        width="160">
                    </el-table-column>
                    <el-table-column
                        align="center"
                        prop="menuName"
                        label="菜单名称"
                        width="160">
                    </el-table-column>
                    <el-table-column
                        align="center"
                        prop="icon"
                        label="菜单图标"
                        width="80">
                        <template #default="scope">
                            <div v-html="scope.row.showIcon"></div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        align="center"
                        prop="menuLevelName"
                        label="菜单级别"
                        width="80">
                    </el-table-column>
                    <el-table-column
                        align="center"
                        prop="menuOrder"
                        label="菜单序号"
                        width="80">
                    </el-table-column>
                    <el-table-column
                        align="center"
                        prop="menuUrl"
                        label="菜单地址"
                        min-width="120">
                    </el-table-column>
                    <el-table-column
                        align="center"
                        prop="menuTypeName"
                        label="展开方式"
                        width="80">
                    </el-table-column>
                    <el-table-column
                        fixed="right"
                        align="center"
                        label="操作"
                        width="240">
                        <template #default="scope">
                            <el-button size="small" type="success"
                                @click="showRequestListDialog(scope.$index, scope.row)">接口</el-button>
                            <el-button size="small" :disabled="!(btOption.btUpdateMenu)"
                                @click="btUpdateMenu(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="small" type="danger"  :disabled="!(btOption.btDeleteMenu)"
                                @click="btDeleteMenu(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </template>
        </table-span>

        <!-- 接口 Dialog -->
        <el-dialog 
            width="960px"
            v-model="requestListDialogOption.isShow" 
            :title="requestListDialogOption.title"
            :close-on-press-escape="false"
            :close-on-click-modal="false"
            @open="requestListDialogOpen"
            @closed="requestListDialogClosed">
            <template #header>
                <div class="dialog_header el-dialog__title">
                    <div>{{requestListDialogOption.title}}</div>
                    <div class="dialog_header_icon" @click="refreshReuqestDialog">
                        <el-icon class="Refresh">
                            <Refresh />
                        </el-icon>
                    </div>
                </div>
            </template>
            <template>
                <el-dialog
                    :title="requestDialogOption.dialogTitle"
                    v-model="requestDialogOption.isShow"
                    append-to-body
                    @close="requestDialogClose"
                    :before-close="requestDialogBeforeClose"
                    :close-on-click-modal="false"
                    :close-on-press-escape="false"
                    top="20vh"
                    width="450px">
                    <el-form ref="requestForm" :model="requestDataForm" :rules="requestDataRules" label-width="80px" size="default">
                        <el-form-item label="请求地址" prop="requestUrl">
                            <el-input v-model="requestDataForm.requestUrl" placeholder="请填写请求地址" :clearable="true"></el-input>
                        </el-form-item>
                        <el-form-item label="权限标识" prop="permissionName">
                            <el-input v-model="requestDataForm.permissionName" placeholder="请填写权限标识" :clearable="true"></el-input>
                        </el-form-item>
                        <el-form-item label="内容描述" prop="btDescribe">
                            <el-input v-model="requestDataForm.btDescribe" placeholder="请填写内容描述" :clearable="true"></el-input>
                        </el-form-item>
                    </el-form>
                    <template #footer>
                        <el-button size="default" @click="requestDialogCancel">取 消</el-button>
                        <el-button size="default" type="primary" @click="requestDialogSave">保存</el-button>
                    </template>
                </el-dialog>
            </template>
            
            <el-table
                :data="requestListDialogOption.tableData"
                size="default"
                height="320"
                max-height="420"
                border
                element-loading-text="加载中"
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(255, 255, 255, 0.8)"
                :show-header="true">
                <el-table-column
                    align="center"
                    type="index"
                    width="50">
                </el-table-column>
                <el-table-column
                    align="left"
                    header-align="center"
                    prop="requestUrl"
                    label="请求地址"
                    min-width="220">
                </el-table-column>                                                    
                <el-table-column
                    align="left"
                    header-align="center"
                    prop="permissionName"
                    label="权限标识"
                    width="180">
                </el-table-column>
                <el-table-column
                    align="center"
                    prop="btDescribe"
                    label="描述"
                    min-width="120">
                </el-table-column>
                <el-table-column
                    align="center"
                    label="操作"
                    min-width="90">
                    <template #header>
                        <el-button type="primary" size="small" :disabled="!(btOption.btSaveRequest)"
                            @click="saveRequest()">新增</el-button>
                    </template>
                    <template #default="menuScope">
                        <el-button size="small" :disabled="!(btOption.btUpdateRequest)"
                            @click="updateRequest(menuScope.$index, menuScope.row)">编辑</el-button>
                        <el-button size="small" type="danger"  :disabled="!(btOption.btDeleteRequest)"
                            @click="deleteRequest(menuScope.$index, menuScope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>

        <!-- 菜单 Dialog -->
        <el-dialog
            :title="menuDialogOption.title"
            v-model="menuDialogOption.isShow"
            :append-to-body="false"
            @close="menuDialogClose"
            :before-close="menuDialogBeforeClose"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            width="450px">
            <template>
                <!-- font icon 选择器 -->
                <el-dialog
                title="icon选择器"
                v-model="fontIconDialogOption.isShow"
                :destroy-on-close="true"
                top="20vh"
                width="790px"
                append-to-body>
                    <div style="width: 100%;height: 480px">
                        <font-icon-select :copySuccessCallback="copySuccess"></font-icon-select>
                    </div>
                </el-dialog>
            </template>
            <el-form ref="menuForm" :model="menuDataForm" :rules="dataRules" label-width="80px" size="default">
                <el-form-item label="菜单名称" prop="menuName">
                    <el-input v-model="menuDataForm.menuName" placeholder="请填写菜单名称" :clearable="true"></el-input>
                </el-form-item>
                <el-form-item label="菜单图标">
                    <el-input v-model="menuDataForm.icon" placeholder="请填写菜单图标" :clearable="true">
                        <template #append>
                            <el-button icon="Search" @click="openSearchIcon"></el-button>
                        </template>
                    </el-input>
                </el-form-item>
                <el-form-item label="菜单级别" prop="menuLevel">
                    <el-select v-model="menuDataForm.menuLevel" placeholder="请选择菜单级别"
                        size="default" @change="menuFormChangeLevel" style="width:100%">
                        <el-option
                                v-for="item in menuLevelList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <template v-if="menuDataForm.menuLevel=='1'">
                    <el-form-item label="父级菜单">
                        <el-select v-model="menuDataForm.parentId" placeholder="请选择父级菜单"
                                   size="default" :disabled="true" style="width:100%">
                            <el-option
                                    v-for="item in parentList"
                                    :key="item.menuId"
                                    :label="item.menuName"
                                    :value="item.menuId">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </template>
                <template v-else>
                    <el-form-item label="父级菜单" prop="parentId">
                        <el-select v-model="menuDataForm.parentId" placeholder="请选择父级菜单"
                                   size="default" :disabled="false" style="width:100%">
                            <el-option
                                    v-for="item in parentList"
                                    :key="item.menuId"
                                    :label="item.menuName"
                                    :value="item.menuId">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </template>

                <template v-if="menuDataForm.menuLevel=='1'">
                    <el-form-item label="菜单地址">
                        <el-input v-model="menuDataForm.menuUrl" placeholder="请填写菜单地址" :clearable="true"></el-input>
                    </el-form-item>
                </template>
                <template v-else>
                    <el-form-item label="菜单地址" prop="menuUrl">
                        <el-input v-model="menuDataForm.menuUrl" placeholder="请填写菜单地址" :clearable="true"></el-input>
                    </el-form-item>
                </template>
                <el-form-item label="展开方式" prop="menuType">
                    <el-select v-model="menuDataForm.menuType" placeholder="请选择展开方式"
                               size="default" style="width:100%">
                        <el-option
                                v-for="item in menuTypeList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="菜单排序" prop="menuOrder">
                    <el-input-number v-model="menuDataForm.menuOrder"
                    :min="1" :max="99" style="width:100%"></el-input-number>
                </el-form-item>
            </el-form>
            <template #footer>
                <el-button size="default" @click="dialogCancel">取 消</el-button>
                <el-button size="default" type="primary" @click="menuDialogSave">保存</el-button>
            </template>
        </el-dialog>
    </div>
</template>


<script>
    import { ElMessage } from 'element-plus'
    import TableSpan from '@/components/table-span.vue';
    import FontIconSelect from '@/components/font-icon-select.vue'
    import {tool} from "@/js/tool.js";

    export default {
        data : function(){
            return {
                btOption: {
                    btSaveMenu: null,
                    btUpdateMenu: null,
                    btDeleteMenu: null,
                    btSaveRequest: null,
                    btUpdateRequest: null,
                    btDeleteRequest: null
                },
                parentList : [],
                menuLevelList : [],
                menuTypeList : [],
                tabelData: {
                    total: 0,
                    size: 10,
                    current: 1,
                    records: []
                },
                menuSearchCondition : {
                    menuName : "",
                    menuLevel : "",
                    parentId : null,
                    menuScope : "",
                    page: 1,
                    size: 10
                },

                requestListDialogOption:{
                    title: "",
                    isShow: false,
                    selectMenu: null,
                    tableData: [],
                },
                requestDialogOption : {
                    dialogTitle : "",
                    isShow : false,
                    dialogType : 0,        //0、新增；1、编辑
                    selectData: null
                },
                requestDataForm : {
                    requestId : 0,
                    menuId : 0,
                    requestUrl : "",
                    permissionName : "",
                    btDescribe : ""
                },
                requestDataRules : {
                    requestUrl: [
                        { required: true, message: '请填写请求地址', trigger: 'blur' },
                    ]
                },

                menuDataForm : {
                    menuName : "",
                    icon : "",
                    menuLevel : "",
                    menuScope : 1,
                    menuType : "",
                    parentId : null,
                    menuUrl : "",
                    menuOrder : 1
                },
                dataRules : {
                    menuName : [
                        { required: true, message: '请输入菜单名称', trigger: 'blur' }
                    ],
                    menuLevel : [
                        { required: true, message: '请选择菜单级别', trigger: 'blur' }
                    ],
                    parentId : [
                        { required: true, message: '请选择父级菜单', trigger: 'blur' }
                    ],
                    menuUrl : [
                        { required: true, message: '请填写页面地址', trigger: 'blur' }
                    ],
                    menuType : [
                        { required: true, message: '请选择页面展开方式', trigger: 'blur' }
                    ],
                    menuOrder : [
                        { required: true, message: '请设置菜单的序号', trigger: 'blur' }
                    ]
                },
                menuDialogOption: {
                    title: "",
                    isShow: false,
                    type: 0,            //0、新增；1、编辑
                    selectData: null
                },
                fontIconDialogOption: {
                    isShow: false
                }
            }
        },
        methods : {
            searchData: function(){
                this.menuSearchCondition.page = 1;
                getParentList(this,this.menuSearchCondition,"2");
            },
            handleSizeChange: function(val){
                this.menuSearchCondition.size = val;
                this.menuSearchCondition.page = 1;

                this.tabelData.size = val;
                this.tabelData.current = 1;
                getParentList(this,this.menuSearchCondition,"2");
            },
            handleCurrentChange: function(val){
                this.menuSearchCondition.page = val;
                this.tabelData.current = val;
                getParentList(this,this.menuSearchCondition,"2");
            },
            btInsertMenu: function(){
                this.menuDialogOption.type = 0;
                this.menuDialogOption.title = "新增菜单";
                this.menuDialogOption.isShow = true;
            },
            btUpdateMenu: function(index,row){
                this.menuDialogOption.type = 1;
                this.menuDialogOption.title = "编辑菜单";
                this.menuDialogOption.isShow = true;
                this.menuDialogOption.selectData = row;

                this.menuDataForm = {
                    menuId : row.menuId,
                    menuName : row.menuName,
                    icon : row.icon,
                    menuLevel : row.menuLevel,
                    menuType : row.menuType,
                    parentId : row.parentId,
                    menuUrl : row.menuUrl,
                    menuOrder : row.menuOrder
                };
                if(row.parentId == -1){
                    this.menuDataForm.parentId = null;
                }
            },
            btDeleteMenu: function(index,row){
                const obj = this;
                const confirmMessage = "是否删除当前选择的菜单：" + row.menuName + "?";
                this.$confirm(confirmMessage).then(function(){
                    const param = {
                        menuId : row.menuId
                    };
                    deleteMenu(obj,param);
                }).catch(function(){

                });
            },
            showRequestListDialog: function(index,row){
                this.requestListDialogOption.title = row.menuName;
                this.requestListDialogOption.isShow = true;
                this.requestListDialogOption.selectMenu = row;
            },
            requestListDialogOpen: function(){
                getRequestList(this,this.requestListDialogOption.selectMenu);
            },
            refreshReuqestDialog: function(){
                getRequestList(this,this.requestListDialogOption.selectMenu);
            },
            requestListDialogClosed: function(){
                this.requestListDialogOption.tableData = [];
                this.requestListDialogOption.title = "";
                this.requestListDialogOption.selectMenu = null;
            },
            menuDialogClose: function(){
                //清除弹出框数据
                this.menuDataForm = {
                    menuId : 0,
                    menuName : "",
                    icon : "",
                    menuLevel : "",
                    menuType : "",
                    parentId : null,
                    menuUrl : "",
                    menuOrder : 1
                };
                this.$refs["menuForm"].clearValidate();
            },
            dialogCancel: function(){
                dialogCloseTips(this);
            },
            menuDialogSave: function(){
                var obj = this;
                this.$refs["menuForm"].validate(function(valid){
                    if (valid) {
                        let param = new Object();
                        for(let item in obj.menuDataForm){
                            param[item] = obj.menuDataForm[item];
                        }
                        param["menuScope"] = 1;
                        if(obj.menuDataForm.menuLevel == 1){
                            param.parentId = -1;
                        }
                        if(obj.menuDialogOption.type == 0){
                            //保存
                            const confirmMessage = "是否保存新增的数据？";
                            obj.$confirm(confirmMessage).then(function(){
                                insertMenu(obj,param);
                            }).catch(function(){});
                        }else {
                            //编辑
                            const confirmMessage = "是否提交修改的数据？";
                            obj.$confirm(confirmMessage).then(function(){
                                updateMenu(obj, param);
                            }).catch(function(){});
                        }
                    } else {
                        return false;
                    }
                });
            },
            menuDialogBeforeClose : function(done){
                dialogCloseTips(this);
            },
            openSearchIcon: function(){
                this.fontIconDialogOption.isShow = true;
            },
            copySuccess: function(){
                ElMessage({
                    showClose: true,
                    message: '复制成功',
                    type: 'success'
                });
            },
            menuFormChangeLevel: function(){
                //选择一级菜单设置父级菜单选项为空
                if(this.menuDataForm.menuLevel == "1"){
                    this.menuDataForm.parentId = null;
                    this.$refs["menuForm"].clearValidate();
                }
            },
            saveRequest: function(){
                const row = this.requestListDialogOption.selectMenu;
                this.requestDialogOption.dialogType = 0;
                this.requestDialogOption.dialogTitle = row.menuName + "-新增接口";
                this.requestDialogOption.isShow = true;
                this.requestDialogOption.selectData = row;
            },
            updateRequest: function(index,row){
                this.requestDialogOption.dialogType = 1;
                this.requestDialogOption.dialogTitle = row.menuName + "-编辑接口";
                this.requestDialogOption.isShow = true;
                this.requestDialogOption.selectData = row;

                this.requestDataForm = {
                    requestId : row.requestId,
                    menuId : row.menuId,
                    requestUrl : row.requestUrl,
                    permissionName : row.permissionName,
                    btDescribe : row.btDescribe
                }
            },
            deleteRequest : function(index,row){
                var obj = this;
                var confirmMessage = "是否删除当前选择的接口";
                this.$confirm(confirmMessage).then(function(){
                    const param = {
                        requestId : row.requestId,
                        status : "1"
                    };
                    deleteRequest(obj,param);
                }).catch(function(){});
            },
            requestDialogClose : function(){
                this.requestDataForm = {
                    menuId : 0,
                    requestUrl : "",
                    permissionName : "",
                    btDescribe : ""
                };
                this.$refs["requestForm"].clearValidate();
                this.requestDialogOption.selectData = null;
            },
            requestDialogBeforeClose : function(){
                requestDialogCloseTips(this);
            },
            requestDialogCancel : function(){
                requestDialogCloseTips(this);
            },
            requestDialogSave: function(){
                var obj = this;
                this.$refs["requestForm"].validate(function(valid){
                    if (valid) {
                        const confirmMessage = "是否保存数据？";
                        if(obj.requestDialogOption.dialogType == 0){
                            //保存
                            obj.$confirm(confirmMessage).then(function(){
                                obj.requestDataForm.menuId = obj.requestDialogOption.selectData.menuId;
                                insertRequest(obj,obj.requestDataForm);
                            }).catch(function(){});
                        }else if(obj.requestDialogOption.dialogType == 1){
                            //编辑
                            obj.$confirm(confirmMessage).then(function(){
                                updateRequest(obj,obj.requestDataForm);
                            }).catch(function(){});
                        }
                    } else {
                        return false;
                    }
                });
            }
        },
        created : function(){
            const menuId = [this.$route.query.menuId]
            const obj = this;
            new tool.getAuthorisedRequest(menuId, this.btOption, function(){
                //获取一级菜单
                var param = {
                    menuLevel: 1,
                    page: 1,
                    size: -1
                };
                getParentList(obj, param, "1");

                //获取菜单列表
                getParentList(obj, obj.menuSearchCondition, "2");
            });

            getSysdict(this);
        },
        components : {
            TableSpan,
            FontIconSelect
        },
    }
    /**
     * 获取一级菜单
     * @param app app对象
     * @param param 获取数据的列表
     * @param type 类型，1、查询一级菜单；2、查询所有菜单；
     */
    function getParentList(app,param,type){
        const url = "/user/menu/list";
        tool.formJsonRequest(url,param,null,function(data){
            if(data.code === "0000"){
                if(type === "1"){
                    app.parentList = data.data.records;
                }else if(type === "2"){
                    app.tabelData.total = data.data.total;
                    app.tabelData.size = data.data.size;
                    app.tabelData.current = data.data.current;
                    app.tabelData.records = data.data.records;

                    for(var i=0;i<app.tabelData.records.length;i++){
                        var item = app.tabelData.records[i];
                        if(item.menuLevel == 1){
                            item["menuLevelName"] = "一级菜单";
                        }else if(item.menuLevel == 2){
                            item["menuLevelName"] = "二级菜单";
                        }
                        if(item.menuType == "0"){
                            item["menuTypeName"] = "当前页面";
                        }else if(item.menuType == "1"){
                            item["menuTypeName"] = "新页签";
                        }

                        //icon
                        if(item.icon){
                            item["showIcon"] = "<i class='" + item.icon + "' style='font-size: 20px'></i>";
                        }
                        item["requestList"] = [];
                    }
                }
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }

    /**
     * 新增菜单信息
     * @param app app对象
     * @param param 获取数据的列表
     */
    function insertMenu(app,param){
        var url = "/user/menu/save";
        tool.formJsonRequest(url,param,null,function(data){
            if(data.code === "0000"){
                ElMessage({
                    showClose: true,
                    message: '菜单保存成功',
                    type: 'success'
                });
                app.menuSearchCondition.page = 1;
                getParentList(app,app.menuSearchCondition,"2");
                app.menuDialogOption.isShow = false;
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }

    /**
     * 更新菜单信息
     * @param app app对象
     * @param param 获取数据的列表
     */
    function updateMenu(app,param){
        var url = "/user/menu/update";
        tool.formJsonRequest(url,param,null,function(data){
            if(data.code === "0000"){
                ElMessage({
                    showClose: true,
                    message: '菜单更新成功',
                    type: 'success'
                });
                app.menuSearchCondition.page = 1;
                getParentList(app,app.menuSearchCondition,"2");
                app.menuDialogOption.isShow = false;
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }

    /**
     * 删除菜单
     * @param app app对象
     * @param param 获取数据的列表
     */
    function deleteMenu(app,param){
        const url = "/user/menu/delete";
        tool.formJsonRequest(url,param,null,function(data){
            if(data.code === "0000"){
                ElMessage({
                    showClose: true,
                    message: '菜单删除成功',
                    type: 'success'
                });
                app.menuSearchCondition.page = 1;
                getParentList(app,app.menuSearchCondition,"2");
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }

    /**
     * 获取页面对应的按钮及请求地址
     * @param app app对象
     * @param param 获取数据的列表
     */
    function getRequestList(app,menuObject){
        var option = {
            "menuId" : menuObject.menuId,
            "size": -1
        };
        var url = "/user/request/list";
        tool.formJsonRequest(url,option,function(){},function(data){
            if(data.code == "0000"){
                //清空数组
               app.requestListDialogOption.tableData = data.data.records;
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }


    /**
     * 新增请求或者按钮
     * @param app app对象
     * @param param 获取数据的列表
     */
    function insertRequest(app,param){
        const url = "/user/request/save";
        tool.formJsonRequest(url,param,null,function(data){
            if(data.code === "0000"){
                ElMessage({
                    showClose: true,
                    message: '接口保存成功',
                    type: 'success'
                });

                getRequestList(app,app.requestListDialogOption.selectMenu);

                app.requestDialogOption.isShow = false;
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }

    /**
     * 更新请求或者按钮信息
     * @param app app对象
     * @param param 获取数据的列表
     */
    function updateRequest(app,param){
        const url = "/user/request/update";
        tool.formJsonRequest(url,param,null,function(data){
            if(data.code === "0000"){
                ElMessage({
                    showClose: true,
                    message: '接口更新成功',
                    type: 'success'
                });
                getRequestList(app,app.requestListDialogOption.selectMenu);

                app.requestDialogOption.isShow = false;
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }

    /**
     * 删除接口信息
     * @param app app对象
     * @param param 获取数据的列表
     */
    function deleteRequest(app,param){
        const url = "/user/request/delete";
        tool.formJsonRequest(url,param,null,function(data){
            if(data.code === "0000"){
                ElMessage({
                    showClose: true,
                    message: '接口删除成功',
                    type: 'success'
                });
                getRequestList(app,app.requestListDialogOption.selectMenu);
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }

    /**
     * 获取字典类型
     * @param app app对象
     */
    function getSysdict(app){
        const url = "/basic/dict/listByType";
        const param = ["menu_level","menu_type"]
        tool.formJsonRequest(url,param,null,function(data){
            if(data.code === "0000"){
                for(let i=0;i<data.data.length;i++){
                    let item = data.data[i];
                    item.value = parseInt(item.value);
                    if(item.type == "menu_level"){
                        app.menuLevelList.push(item);
                    }else if(item.type == "menu_type"){
                        app.menuTypeList.push(item);
                    }
                }
            }else{
                ElMessage({
                    showClose: true,
                    message: data.message,
                    type: 'error'
                });
            }
        });
    }


    /**
     * 关闭dialog的提示信息
     * @param app
     */
    function dialogCloseTips(app) {
        var confirmMessage = "";
        var obj = app;
        if(app.requestDialogOption.dialogType == 0){
            confirmMessage = "是否放弃新增菜单?";
        }else if(app.requestDialogOption.dialogType == 1){
            confirmMessage = "是否放弃编辑菜单?";
        }
        app.$confirm(confirmMessage).then(function(){
            obj.menuDialogOption.isShow = false;
        }).catch(function(){});
    }

    /**
     * 关闭dialog的提示信息
     * @param app
     */
    function requestDialogCloseTips(app) {
        var confirmMessage = "";
        var obj = app;
        if(app.requestDialogOption.dialogType == 0){
            confirmMessage = "是否放弃新增接口?";
        }else if(app.requestDialogOption.dialogType == 1){
            confirmMessage = "是否放弃编辑接口?";
        }
        app.$confirm(confirmMessage).then(function(){
            obj.requestDialogOption.isShow = false;
            app.requestDialogOption.selectData = null;
        }).catch(function(){

        });
    }
</script>

<style scoped>
    .menu_manage_span{
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        font-family: Microsoft YaHei,Heiti SC,tahoma,arial,Hiragino Sans GB,"\5B8B\4F53",sans-serif;
        flex-wrap : wrap;
    }
    .search_item_span{
        max-width: 190px;
        height: auto;
        margin-top: 5px;
        margin-left: 10px;
    }
    .search_item_fix_width{
        width: 190px;
    }
    .bt_tool_span{
        width: 100%;
        height: auto;
    }
    .expand_span{
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    .dialog_header{
        display: flex;
        flex-direction: row;
        align-items: center;
    }
    .dialog_header .dialog_header_icon{
        display: flex;
        flex-direction: row;
        align-items: center;
        margin-left: 6px;
        cursor: pointer;
    }
</style>